const multer = require('multer');
const path = require('path');
module.exports = function(req, res, next) {
		var filename = '';
		var storage = multer.diskStorage({
			destination: function(req, file, cb) {
				cb(null, path.resolve(__dirname,'../public/upload'))
			},
			filename: function(req, file, cb) {
				let extname = path.extname(file.originalname);
				filename = file.fieldname + '-' + Date.now() + extname;
				cb(null,filename)
			}
		})

		var upload = multer({ storage: storage }).single('companyLogo');
		//将图片文件保存到本地磁盘的操作
		upload(req, res, function(err) {		
			if(err){
				console.log(err);
			}else{
				req.imagename = filename;
				next();
			}	
		})
			
		
}
